<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>手机端touch</title>
    <script src="http://47.104.209.44/base/js/jquery-1.10.1.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        #app {
            width: 200px;
            height: 200px;
            background: darkorchid;
        }

        .page {
            width: 100%;
            height: 700px;
            margin-top: 400px;
            background: darkturquoise;
        }
    </style>
</head>

<body>
    <div id="app" onclick="todoclick(event)" ondbclick="tododbclick(event)">
        App
    </div>

    <div class="page">

    </div>

    <script>
        function todoclick(e) {
            console.log(e)
        }
        function tododbclick(e) {
            console.log("tododbclick")
        }
        var app = document.getElementById("app")
        app.addEventListener("click", function (e) {
            console.log(e.clientX)
        }, false)

        var page = document.querySelectorAll('.page')[0]
        var startY = 0;
        var endY = 0
        page.addEventListener("touchstart", function (e) {
            var e = e || window.event
            console.log(e)
            var touch = e.touches[0]
            startY = touch.clientY
            page.innerHTML = `<p> clientX :  ${touch.clientX}</p>`
                + `<p> clientY :  ${touch.clientY}</p>`
                + `<p> pageX :  ${touch.pageX}</p>`
                + `<p> pageY :  ${touch.pageY}</p>`
                + `<p> screenX :  ${touch.screenX}</p>`
                + `<p> screenY :  ${touch.screenY}</p>`
                + `<p> 滑动的高度 :  ${touch.pageY - touch.clientY}</p>`


        }, false)

        page.addEventListener("touchmove", function (e) {
            var e = e || window.event
            console.log(e)
            var touch = e.touches[0]
            endY = touch.clientY
            page.innerHTML = `<p> clientX :  ${touch.clientX}</p>`
                + `<p> clientY :  ${touch.clientY}</p>`
                + `<p> pageX :  ${touch.pageX}</p>`
                + `<p> pageY :  ${touch.pageY}</p>`
                + `<p> screenX :  ${touch.screenX}</p>`
                + `<p> screenY :  ${touch.screenY}</p>`
                + `<p> 滑动的高度 :  ${touch.pageY - touch.clientY}</p>`


        }, false)


        page.addEventListener("touchend", function (e) {
            var e = e || window.event
            console.log("touchend - 手势已经离开屏幕")
            console.log(e)
            console.log(e.changedTouches[0])   // 最后一次的手势集合
            if (startY > endY) {
                page.innerHTML = "<p>up 向上滑动</p>"
            } else {
                page.innerHTML = "<p>down 向下滑动</p>"
            }

        }, false)

        // jQuery 可以绑定 touch系列事件 但是不能获取事件触摸对象信息
        $(".page").on("touchmove", function (e) {
            console.log("jQuery -- touch ")
            console.log(e)
        })

        var width = document.body.clientWidth || document.documentElement.clientWidth
        console.log(width)
        var dpr = window.devicePixelRatio; // 设备像素密度比    越大  手机越贵 
        console.log(dpr)


    </script>
</body>

</html>